import codecs
import os

import xlrd
import xlwt

import numpy as np
import pandas as pd
import sys

print(sys.path)
sys.path.append("c:\\users\\newuser\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages")

from test import predict
import Levenshtein


def writeTestCase():
    path = "E:\命名体识别\caseDirectory"
    for file in os.walk(path):
        fileNameList = file[2]
        for fileName in fileNameList:
            id = str(fileName).split("_")[1]
            id = id.split(".")[0]
            ExcelFile = pd.read_excel(path + "\\" + str(fileName), header=None, index=None).fillna(0)
            y = np.array(ExcelFile.values)
            row = y.shape[0]
            xls = xlwt.Workbook()
            sheet = xls.add_sheet('sheet1', cell_overwrite_ok=True)
            j = 0
            for i in range(0, row):
                print(y[i, 0])
                resultAction, resultTarget, resultData = predict(y[i, 0])

                resultAction = str(resultAction).split('***')[0]
                resultTarget = str(resultTarget).replace('***', '').replace("和", "").replace("、", "")
                resultData = "".join(resultData).replace('***', '')

                sheet.write(j, 0, resultAction)
                sheet.write(j, 1, resultTarget)
                sheet.write(j, 2, resultData)
                sheet.write(j, 3, y[i, 1])
                j += 1

            # xls.save('testCasePredict.xls')
            xls.save('xlsToTuples/testCasePredict_' + id + '.xls')

writeTestCase()